package com.lxmes.sales.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.sales.domain.AssetKucun;
import com.lxmes.sales.service.IAssetKucunService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 资产库存
Controller
 *
 * @author zhangzhiyu
 * @date 2024-08-28
 */
@Api(tags = "资产库存")
@RestController
@RequestMapping("/sales/AssetKucun")
public class AssetKucunController extends BaseController
{
    @Autowired
    private IAssetKucunService assetKucunService;

    /**
     * 查询资产库存列表
     */
    @ApiOperation("查询资产库存列表")
    @PreAuthorize("@ss.hasPermi('sales:AssetKucun:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetKucun assetKucun)
    {
        startPage();
        List<AssetKucun> list = assetKucunService.selectAssetKucunList(assetKucun);
        return getDataTable(list);
    }

    /**
     * 导出资产库存
列表
     */
    @ApiOperation("导出资产库存列表")
    @PreAuthorize("@ss.hasPermi('sales:AssetKucun:export')")
    @Log(title = "资产库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetKucun assetKucun)
    {
        List<AssetKucun> list = assetKucunService.selectAssetKucunList(assetKucun);
        ExcelUtil<AssetKucun> util = new ExcelUtil<AssetKucun>(AssetKucun.class);
        util.exportExcel(response, list, "资产库存数据");
    }

    /**
     * 获取资产库存
详细信息
     */
    @ApiOperation("获取资产库存详细信息")
    @PreAuthorize("@ss.hasPermi('sales:AssetKucun:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(assetKucunService.selectAssetKucunById(id));
    }

    /**
     * 新增资产库存

     */
    @ApiOperation("新增资产库存")
    @PreAuthorize("@ss.hasPermi('sales:AssetKucun:add')")
    @Log(title = "资产库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetKucun assetKucun)
    {
        return toAjax(assetKucunService.insertAssetKucun(assetKucun));
    }

    /**
     * 修改资产库存

     */
    @ApiOperation("修改资产库存")
    @PreAuthorize("@ss.hasPermi('sales:AssetKucun:edit')")
    @Log(title = "资产库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetKucun assetKucun)
    {
        return toAjax(assetKucunService.updateAssetKucun(assetKucun));
    }

    /**
     * 删除资产库存

     */
    @ApiOperation("删除资产库存")
    @PreAuthorize("@ss.hasPermi('sales:AssetKucun:remove')")
    @Log(title = "资产库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetKucunService.deleteAssetKucunByIds(ids));
    }
    /**
     * 导入资产库存

     */
    @Log(title = "资产库存", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<AssetKucun> util = new ExcelUtil<>(AssetKucun.class);
        List<AssetKucun> assetKucunList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = assetKucunService.imporIteminfo(assetKucunList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<AssetKucun> util = new ExcelUtil<>(AssetKucun.class);
        util.importTemplateExcel(response,"资产库存");
    }
}
